﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClientWPF.localhost;

namespace ClientWPF
{
    public partial class MainWindow : Window
    {
        Service1 service = new Service1();

        public MainWindow()
        {
            InitializeComponent();
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        }

        private void LogInButton_Click(object sender, RoutedEventArgs e)
        {
            User user = new User();
            user.Name = NameBox.Text;
            user.Password = PasswordBox.Password;
            if (service.CheckUserExist(user))
            {
                if (service.CheckUserPass(user))
                {
                    if (service.CheckIfAdmin(user))
                    {
                        var panel = new AdminPanel();
                        Close();
                        panel.Show();
                    }
                    else
                    {
                        var panel = new UserPanel();
                        Close();
                        panel.Show();
                    }
                }
                else MessageBox.Show("Password is incorrect!");
            }
            else MessageBox.Show("User " + user.Name + " doesn't exist!");
        }

        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            var form = new RegisterForm();
            Close();
            form.Show();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
